{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 15.6 \u4eceC\u8bed\u8a00\u4e2d\u8c03\u7528Python\u4ee3\u7801\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u60f3\u5728C\u4e2d\u5b89\u5168\u7684\u6267\u884c\u67d0\u4e2aPython\u8c03\u7528\u5e76\u8fd4\u56de\u7ed3\u679c\u7ed9C\u3002\n\u4f8b\u5982\uff0c\u4f60\u60f3\u5728C\u8bed\u8a00\u4e2d\u4f7f\u7528\u67d0\u4e2aPython\u51fd\u6570\u4f5c\u4e3a\u4e00\u4e2a\u56de\u8c03\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5728C\u8bed\u8a00\u4e2d\u8c03\u7528Python\u975e\u5e38\u7b80\u5355\uff0c\u4e0d\u8fc7\u6d89\u53ca\u5230\u4e00\u4e9b\u5c0f\u7a8d\u95e8\u3002\n\u4e0b\u9762\u7684C\u4ee3\u7801\u544a\u8bc9\u4f60\u600e\u6837\u5b89\u5168\u7684\u8c03\u7528\uff1a"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ":: c"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#include <Python.h>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "PyObject *args;\nPyObject *kwargs;\nPyObject *result = 0;\ndouble retval;"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "/* Make sure we own the GIL */\nPyGILState_STATE state = PyGILState_Ensure();"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "/* Verify that func is a proper callable */\nif (!PyCallable_Check(func)) {"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "}\n/* Build arguments */\nargs = Py_BuildValue(\u201c(dd)\u201d, x, y);\nkwargs = NULL;"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "/* Call the function */\nresult = PyObject_Call(func, args, kwargs);\nPy_DECREF(args);\nPy_XDECREF(kwargs);"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "/* Check for Python exceptions (if any) */\nif (PyErr_Occurred()) {"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "/* Verify the result is a float object */\nif (!PyFloat_Check(result)) {"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "/* Create the return value */\nretval = PyFloat_AsDouble(result);\nPy_DECREF(result);"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "/* Restore previous GIL state and return */\nPyGILState_Release(state);\nreturn retval;"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8981\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u4f60\u9700\u8981\u83b7\u53d6\u4f20\u9012\u8fc7\u6765\u7684\u67d0\u4e2a\u5df2\u5b58\u5728Python\u8c03\u7528\u7684\u5f15\u7528\u3002\n\u6709\u5f88\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u4f60\u8fd9\u6837\u505a\uff0c\n\u6bd4\u5982\u5c06\u4e00\u4e2a\u53ef\u8c03\u7528\u5bf9\u8c61\u4f20\u7ed9\u4e00\u4e2a\u6269\u5c55\u6a21\u5757\u6216\u76f4\u63a5\u5199C\u4ee3\u7801\u4ece\u5df2\u5b58\u5728\u6a21\u5757\u4e2d\u63d0\u53d6\u51fa\u6765\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50\u7528\u6765\u5c55\u793a\u4ece\u4e00\u4e2a\u5d4c\u5165\u7684Python\u89e3\u91ca\u5668\u4e2d\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "#include <Python.h>\n\n/* Definition of call_func() same as above */\n...\n\n/* Load a symbol from a module */\nPyObject *import_name(const char *modname, const char *symbol) {\n  PyObject *u_name, *module;\n  u_name = PyUnicode_FromString(modname);\n  module = PyImport_Import(u_name);\n  Py_DECREF(u_name);\n  return PyObject_GetAttrString(module, symbol);\n}\n\n/* Simple embedding example */\nint main() {\n  PyObject *pow_func;\n  double x;\n\n  Py_Initialize();\n  /* Get a reference to the math.pow function */\n  pow_func = import_name(\"math\",\"pow\");\n\n  /* Call it using our call_func() code */\n  for (x = 0.0; x < 10.0; x += 0.1) {\n    printf(\"%0.2f %0.2f\\n\", x, call_func(pow_func,x,2.0));\n  }\n  /* Done */\n  Py_DECREF(pow_func);\n  Py_Finalize();\n  return 0;\n}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8981\u6784\u5efa\u4f8b\u5b50\u4ee3\u7801\uff0c\u4f60\u9700\u8981\u7f16\u8bd1C\u5e76\u5c06\u5b83\u94fe\u63a5\u5230Python\u89e3\u91ca\u5668\u3002\n\u4e0b\u9762\u7684Makefile\u53ef\u4ee5\u6559\u4f60\u600e\u6837\u505a\uff08\u4e0d\u8fc7\u5728\u4f60\u673a\u5668\u4e0a\u9762\u9700\u8981\u4e00\u4e9b\u914d\u7f6e\uff09\u3002"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "all::\n        cc -g embed.c -I/usr/local/include/python3.3m \\\n          -L/usr/local/lib/python3.3/config-3.3m -lpython3.3m"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u7f16\u8bd1\u5e76\u8fd0\u884c\u4f1a\u4ea7\u751f\u7c7b\u4f3c\u4e0b\u9762\u7684\u8f93\u51fa\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "0.00 0.00\n0.10 0.01\n0.20 0.04\n0.30 0.09\n0.40 0.16\n..."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4e0b\u9762\u662f\u4e00\u4e2a\u7a0d\u5fae\u4e0d\u540c\u7684\u4f8b\u5b50\uff0c\u5c55\u793a\u4e86\u4e00\u4e2a\u6269\u5c55\u51fd\u6570\uff0c\n\u5b83\u63a5\u53d7\u4e00\u4e2a\u53ef\u8c03\u7528\u5bf9\u8c61\u548c\u5176\u4ed6\u53c2\u6570\uff0c\u5e76\u5c06\u5b83\u4eec\u4f20\u9012\u7ed9 call_func() \u6765\u505a\u6d4b\u8bd5\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "/* Extension function for testing the C-Python callback */\nPyObject *py_call_func(PyObject *self, PyObject *args) {\n  PyObject *func;\n\n  double x, y, result;\n  if (!PyArg_ParseTuple(args,\"Odd\", &func,&x,&y)) {\n    return NULL;\n  }\n  result = call_func(func, x, y);\n  return Py_BuildValue(\"d\", result);\n}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f7f\u7528\u8fd9\u4e2a\u6269\u5c55\u51fd\u6570\uff0c\u4f60\u8981\u50cf\u4e0b\u9762\u8fd9\u6837\u6d4b\u8bd5\u5b83\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import sample\ndef add(x,y):\n    return x+y\nsample.call_func(add,3,4)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5982\u679c\u4f60\u5728C\u8bed\u8a00\u4e2d\u8c03\u7528Python\uff0c\u8981\u8bb0\u4f4f\u6700\u91cd\u8981\u7684\u662fC\u8bed\u8a00\u4f1a\u662f\u4e3b\u4f53\u3002\n\u4e5f\u5c31\u662f\u8bf4\uff0cC\u8bed\u8a00\u8d1f\u8d23\u6784\u9020\u53c2\u6570\u3001\u8c03\u7528Python\u51fd\u6570\u3001\u68c0\u67e5\u5f02\u5e38\u3001\u68c0\u67e5\u7c7b\u578b\u3001\u63d0\u53d6\u8fd4\u56de\u503c\u7b49\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f5c\u4e3a\u7b2c\u4e00\u6b65\uff0c\u4f60\u5fc5\u987b\u5148\u6709\u4e00\u4e2a\u8868\u793a\u4f60\u5c06\u8981\u8c03\u7528\u7684Python\u53ef\u8c03\u7528\u5bf9\u8c61\u3002\n\u8fd9\u53ef\u4ee5\u662f\u4e00\u4e2a\u51fd\u6570\u3001\u7c7b\u3001\u65b9\u6cd5\u3001\u5185\u7f6e\u65b9\u6cd5\u6216\u5176\u4ed6\u4efb\u610f\u5b9e\u73b0\u4e86 __call__() \u64cd\u4f5c\u7684\u4e1c\u897f\u3002\n\u4e3a\u4e86\u786e\u4fdd\u662f\u53ef\u8c03\u7528\u7684\uff0c\u53ef\u4ee5\u50cf\u4e0b\u9762\u7684\u4ee3\u7801\u8fd9\u6837\u5229\u7528 PyCallable_Check() \u505a\u68c0\u67e5\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "double call_func(PyObject *func, double x, double y) {\n  ...\n  /* Verify that func is a proper callable */\n  if (!PyCallable_Check(func)) {\n    fprintf(stderr,\"call_func: expected a callable\\n\");\n    goto fail;\n  }\n  ..."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5728C\u4ee3\u7801\u91cc\u5904\u7406\u9519\u8bef\u4f60\u9700\u8981\u683c\u5916\u7684\u5c0f\u5fc3\u3002\u4e00\u822c\u6765\u8bb2\uff0c\u4f60\u4e0d\u80fd\u4ec5\u4ec5\u629b\u51fa\u4e00\u4e2aPython\u5f02\u5e38\u3002\n\u9519\u8bef\u5e94\u8be5\u4f7f\u7528C\u4ee3\u7801\u65b9\u5f0f\u6765\u88ab\u5904\u7406\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u6253\u7b97\u5c06\u5bf9\u9519\u8bef\u7684\u63a7\u5236\u4f20\u7ed9\u4e00\u4e2a\u53eb abort() \u7684\u9519\u8bef\u5904\u7406\u5668\u3002\n\u5b83\u4f1a\u7ed3\u675f\u6389\u6574\u4e2a\u7a0b\u5e8f\uff0c\u5728\u771f\u5b9e\u73af\u5883\u4e0b\u9762\u4f60\u5e94\u8be5\u8981\u5904\u7406\u7684\u66f4\u52a0\u4f18\u96c5\u4e9b\uff08\u8fd4\u56de\u4e00\u4e2a\u72b6\u6001\u7801\uff09\u3002\n\u4f60\u8981\u8bb0\u4f4f\u7684\u662f\u5728\u8fd9\u91ccC\u662f\u4e3b\u89d2\uff0c\u56e0\u6b64\u5e76\u6ca1\u6709\u8ddf\u629b\u51fa\u5f02\u5e38\u76f8\u5bf9\u5e94\u7684\u64cd\u4f5c\u3002\n\u9519\u8bef\u5904\u7406\u662f\u4f60\u5728\u7f16\u7a0b\u65f6\u5fc5\u987b\u8981\u8003\u8651\u7684\u4e8b\u60c5\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u76f8\u5bf9\u6765\u8bb2\u5f88\u7b80\u5355\u2014\u2014\u53ea\u9700\u8981\u4f7f\u7528 PyObject_Call() \uff0c\n\u4f20\u4e00\u4e2a\u53ef\u8c03\u7528\u5bf9\u8c61\u7ed9\u5b83\u3001\u4e00\u4e2a\u53c2\u6570\u5143\u7ec4\u548c\u4e00\u4e2a\u53ef\u9009\u7684\u5173\u952e\u5b57\u5b57\u5178\u3002\n\u8981\u6784\u5efa\u53c2\u6570\u5143\u7ec4\u6216\u5b57\u5178\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 Py_BuildValue() ,\u5982\u4e0b\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "double call_func(PyObject *func, double x, double y) {\n  PyObject *args;\n  PyObject *kwargs;\n\n  ...\n  /* Build arguments */\n  args = Py_BuildValue(\"(dd)\", x, y);\n  kwargs = NULL;\n\n  /* Call the function */\n  result = PyObject_Call(func, args, kwargs);\n  Py_DECREF(args);\n  Py_XDECREF(kwargs);\n  ..."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5982\u679c\u6ca1\u6709\u5173\u952e\u5b57\u53c2\u6570\uff0c\u4f60\u53ef\u4ee5\u4f20\u9012NULL\u3002\u5f53\u4f60\u8981\u8c03\u7528\u51fd\u6570\u65f6\uff0c\n\u9700\u8981\u786e\u4fdd\u4f7f\u7528\u4e86 Py_DECREF() \u6216\u8005 Py_XDECREF() \u6e05\u7406\u53c2\u6570\u3002\n\u7b2c\u4e8c\u4e2a\u51fd\u6570\u76f8\u5bf9\u5b89\u5168\u70b9\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u4f20\u9012NULL\u6307\u9488\uff08\u76f4\u63a5\u5ffd\u7565\u5b83\uff09\uff0c\n\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u4f7f\u7528\u5b83\u6765\u6e05\u7406\u53ef\u9009\u7684\u5173\u952e\u5b57\u53c2\u6570\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8c03\u7528\u5b8cPython\u51fd\u6570\u4e4b\u540e\uff0c\u4f60\u5fc5\u987b\u68c0\u67e5\u662f\u5426\u6709\u5f02\u5e38\u53d1\u751f\u3002\nPyErr_Occurred() \u51fd\u6570\u53ef\u88ab\u7528\u6765\u505a\u8fd9\u4ef6\u4e8b\u3002\n\u5bf9\u4e8e\u5f02\u5e38\u7684\u5904\u7406\u5c31\u6709\u70b9\u9ebb\u70e6\u4e86\uff0c\u7531\u4e8e\u662f\u7528C\u8bed\u8a00\u5199\u7684\uff0c\u6ca1\u6709Python\u90a3\u6837\u7684\u5f02\u5e38\u673a\u5236\u3002\n\u56e0\u6b64\uff0c\u4f60\u5fc5\u987b\u8981\u8bbe\u7f6e\u4e00\u4e2a\u5f02\u5e38\u72b6\u6001\u7801\uff0c\u6253\u5370\u5f02\u5e38\u4fe1\u606f\u6216\u5176\u4ed6\u76f8\u5e94\u5904\u7406\u3002\n\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u9009\u62e9\u4e86\u7b80\u5355\u7684 abort() \u6765\u5904\u7406\u3002\u53e6\u5916\uff0c\u4f20\u7edfC\u7a0b\u5e8f\u5458\u53ef\u80fd\u4f1a\u76f4\u63a5\u8ba9\u7a0b\u5e8f\u5954\u6e83\u3002"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "...\n/* Check for Python exceptions (if any) */\nif (PyErr_Occurred()) {\n  PyErr_Print();\n  goto fail;\n}\n...\nfail:\n  PyGILState_Release(state);\n  abort();"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4ece\u8c03\u7528Python\u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e2d\u63d0\u53d6\u4fe1\u606f\u901a\u5e38\u8981\u8fdb\u884c\u7c7b\u578b\u68c0\u67e5\u548c\u63d0\u53d6\u503c\u3002\n\u8981\u8fd9\u6837\u505a\u7684\u8bdd\uff0c\u4f60\u5fc5\u987b\u4f7f\u7528Python\u5bf9\u8c61\u5c42\u4e2d\u7684\u51fd\u6570\u3002\n\u5728\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e86 PyFloat_Check() \u548c PyFloat_AsDouble() \u6765\u68c0\u67e5\u548c\u63d0\u53d6Python\u6d6e\u70b9\u6570\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u6700\u540e\u4e00\u4e2a\u95ee\u9898\u662f\u5bf9\u4e8ePython\u5168\u5c40\u9501\u7684\u7ba1\u7406\u3002\n\u5728C\u8bed\u8a00\u4e2d\u8bbf\u95eePython\u7684\u65f6\u5019\uff0c\u4f60\u9700\u8981\u786e\u4fddGIL\u88ab\u6b63\u786e\u7684\u83b7\u53d6\u548c\u91ca\u653e\u4e86\u3002\n\u4e0d\u7136\u7684\u8bdd\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u89e3\u91ca\u5668\u8fd4\u56de\u9519\u8bef\u6570\u636e\u6216\u8005\u76f4\u63a5\u5954\u6e83\u3002\n\u8c03\u7528 PyGILState_Ensure() \u548c PyGILState_Release() \u53ef\u4ee5\u786e\u4fdd\u4e00\u5207\u90fd\u80fd\u6b63\u5e38\u3002"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "double call_func(PyObject *func, double x, double y) {\n  ...\n  double retval;\n\n  /* Make sure we own the GIL */\n  PyGILState_STATE state = PyGILState_Ensure();\n  ...\n  /* Code that uses Python C API functions */\n  ...\n  /* Restore previous GIL state and return */\n  PyGILState_Release(state);\n  return retval;\n\nfail:\n  PyGILState_Release(state);\n  abort();\n}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4e00\u65e6\u8fd4\u56de\uff0cPyGILState_Ensure() \u53ef\u4ee5\u786e\u4fdd\u8c03\u7528\u7ebf\u7a0b\u72ec\u5360Python\u89e3\u91ca\u5668\u3002\n\u5c31\u7b97C\u4ee3\u7801\u8fd0\u884c\u4e8e\u53e6\u5916\u4e00\u4e2a\u89e3\u91ca\u5668\u4e0d\u77e5\u9053\u7684\u7ebf\u7a0b\u4e5f\u6ca1\u4e8b\u3002\n\u8fd9\u65f6\u5019\uff0cC\u4ee3\u7801\u53ef\u4ee5\u81ea\u7531\u7684\u4f7f\u7528\u4efb\u4f55\u5b83\u60f3\u8981\u7684Python C-API \u51fd\u6570\u3002\n\u8c03\u7528\u6210\u529f\u540e\uff0cPyGILState_Release()\u88ab\u7528\u6765\u5c06\u89e3\u91ca\u5668\u6062\u590d\u5230\u539f\u59cb\u72b6\u6001\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8981\u6ce8\u610f\u7684\u662f\u6bcf\u4e00\u4e2a PyGILState_Ensure()\n\u8c03\u7528\u5fc5\u987b\u8ddf\u7740\u4e00\u4e2a\u5339\u914d\u7684 PyGILState_Release() \u8c03\u7528\u2014\u2014\u5373\u4fbf\u6709\u9519\u8bef\u53d1\u751f\u3002\n\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a goto \u8bed\u53e5\u770b\u4e0a\u53bb\u662f\u4e2a\u53ef\u6015\u7684\u8bbe\u8ba1\uff0c\n\u4f46\u662f\u5b9e\u9645\u4e0a\u6211\u4eec\u4f7f\u7528\u5b83\u6765\u5c06\u63a7\u5236\u6743\u8f6c\u79fb\u7ed9\u4e00\u4e2a\u666e\u901a\u7684exit\u5757\u6765\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\n\u5728 fail: \u6807\u7b7e\u540e\u9762\u7684\u4ee3\u7801\u548cPython\u7684 final: \u5757\u7684\u7528\u9014\u662f\u4e00\u6837\u7684\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5982\u679c\u4f60\u4f7f\u7528\u6240\u6709\u8fd9\u4e9b\u7ea6\u5b9a\u6765\u7f16\u5199C\u4ee3\u7801\uff0c\u5305\u62ec\u5bf9GIL\u7684\u7ba1\u7406\u3001\u5f02\u5e38\u68c0\u67e5\u548c\u9519\u8bef\u68c0\u67e5\uff0c\n\u4f60\u4f1a\u53d1\u73b0\u4eceC\u8bed\u8a00\u4e2d\u8c03\u7528Python\u89e3\u91ca\u5668\u662f\u53ef\u9760\u7684\u2014\u2014\u5c31\u7b97\u518d\u590d\u6742\u7684\u7a0b\u5e8f\uff0c\u7528\u5230\u4e86\u9ad8\u7ea7\u7f16\u7a0b\u6280\u5de7\u6bd4\u5982\u591a\u7ebf\u7a0b\u90fd\u6ca1\u95ee\u9898\u3002"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}